<?php

include_once 'element.php';

define('CODE_AVA', 'http://localhost/xampp-data/sharkload/maniaplanet/download_ava.php'); //TODO

class Avatar implements Element {

	private $data; //array

	public function __construct($data){
		$this->data = $data;
	}
	
	private function formatFilename($filename){
		$filename = preg_replace('/(\.\w*$)/i', '', $filename);//entfernt dateiendung
		return  preg_replace('/(_+|\.+)/', ' ', $filename);//entfernt '_' und '.'
	}

	public function showSquare($pos){
		$code = '
			<quad posn="0 0 -3" sizen="40 40" halign="center" valign="center" style="Bgs1InRace" substyle="BgCard3" />
			<quad posn="0 0 0" sizen="35 35" halign="center" valign="center" image="'.$this->data->url.'"/>
			<quad posn="20 -20 3" sizen="10 10" halign="right" valign="bottom" style="Icons64x64_1" substyle="ArrowDown" manialink="'.CODE_AVA.'?id='.$this->data->ID.'" />
			<!--<quad posn="-20 -20 3" sizen="10 10" halign="left" valign="bottom" style="Icons64x64_1" substyle="Add" />-->
		';
		$frame = '<frame posn="'.$pos.'">'.$code.'</frame>';
		return $frame;
	}

	public function showRectangle($pos){
		$code = '
			<quad posn="20 0 -3" sizen="80 40" halign="center" valign="center" style="Bgs1InRace" substyle="BgCard3" />
			<quad posn="0 0 0" sizen="35 35" halign="center" valign="center" image="'.$this->data->url.'"/>
			<quad posn="20 -20 3" sizen="10 10" halign="right" valign="bottom" style="Icons64x64_1" substyle="ArrowDown" manialink="'.CODE_AVA.'?id='.$this->data->ID.'" />
			<label posn="20 10 1" sizen="35 5" halign="left" valign="bottom" style="TextButtonBig" text="$09f'.$this->formatFilename($this->data->name).'" />
			<label posn="20 5 1" sizen="35 5" halign="left" valign="bottom" style="TextCardSmallScores2" text="by: '.$this->data->nickname.'" />
			<label posn="20 -10 1" sizen="35 5" halign="left" valign="bottom" style="TextCardSmallScores2" text="'.$this->data->date.'" />
			<label posn="20 -15 1" sizen="35 5" halign="left" valign="bottom" style="TextCardSmallScores2" text="Downloads: '.$this->data->downloads.'" />
		';
		$frame = '<frame posn="'.$pos.'">'.$code.'</frame>';
		return $frame;
	}

	public function showLine($pos){
		$code = '
			<quad posn="1 0 -1" sizen="255.5 5" halign="left" valign="bottom" style="Bgs1InRace" substyle="BgCard3" manialink="'.CODE_AVA.'?id='.$this->data->ID.'" />
			<quad posn="2 0.5 0" sizen="4 4" halign="left" valign="bottom" image="'.$this->data->url.'"/>
			<label posn="11 0 0" sizen="18 5" halign="left" valign="bottom" style="TextCardSmallScores2" text="'.$this->data->ID.'" />
			<label posn="31 0 0" sizen="68 5" halign="left" valign="bottom" style="TextCardSmallScores2" text="'.$this->data->name.'" />
			<label posn="101 0 0" sizen="38 5" halign="left" valign="bottom" style="TextCardSmallScores2" text="'.$this->data->nickname.'" />
			<label posn="141 0 0" sizen="38 5" halign="left" valign="bottom" style="TextCardSmallScores2" text="'.$this->data->login.'" />
			<label posn="181 0 0" sizen="28 5" halign="left" valign="bottom" style="TextCardSmallScores2" text="'.$this->data->downloads.'" />
			<label posn="211 0 0" sizen="38 5" halign="left" valign="bottom" style="TextCardSmallScores2" text="'.$this->data->date.'" />
			<quad posn="251 0 0" sizen="5 5" halign="left" valign="bottom" style="Icons64x64_1" substyle="ArrowDown" manialink="'.CODE_AVA.'?id='.$this->data->ID.'" />
		';
		$frame = '<frame posn="'.$pos.'">'.$code.'</frame>';
		return $frame;
	}
}

?>